<?php
include('../../include/functions.inc.php');
include('../../include/inputbuilder.inc.php');
include('../../include/maintenance.inc.php');

$mStudents = unserialize($_SESSION['mStudents']);

$builder = new InputBuilder();
$builder->db = $db;

$tabs = $db->query_select('cllg_table_tab', "TABLE_NAME='cllg_student'");
$arrEmpresas = $db->query_select('cllg_empresa');
?>
<style type="text/css">
    .custom-combobox {
        position: relative;
        display: inline-block;
    }
    .custom-combobox-toggle {
        position: absolute;
        top: 0;
        bottom: 0;
        margin-left: -1px;
        padding: 0;
        /* support: IE7 */
        *height: 1.7em;
        *top: 0.1em;
    }
    .custom-combobox-input {
        margin: 0;
        padding: 0.3em;
    }
</style>
<form id="<?php echo $mStudents->formName; ?>" name="<?php echo $mStudents->formName; ?>" method="post" action="<?php echo $mStudents->saveNewUrlPage; ?>">
    <div id="panel" class="">
                <ul class="nav nav-tabs">
                    <?php
                    $ix = 0;
                    foreach ($tabs as $t) {
                        $ix++;
                        ?>
                        <li class="active" style="font-weight:bolder" tabindex="<?php echo $ix; ?>"><a><?php echo $t["CAPTION"]; ?></a></li>
                    <?php } ?>
                </ul>
                <div class="">
                    <?php
                    $ix = 0;
                    foreach ($tabs as $t) {
                        $ix++;
                        ?>
                <div class="TabbedPanelsContent">
                    <table class=""  width="100%" border="0" cellspacing="0" cellpadding="0">
                        <tr>
                            <th colspan="2">
                                <div class="btn-group" style="margin-left:60%">
                                    <input type="button" class="btn btn-info" name="<?php echo $ix; ?>cmdOk" id="cmdOk<?php echo $ix; ?>" value="Guardar" onClick="javascript:formOkBt($(this.form),newAction);if(jQuery('#FOTO').val().length > 0 ) { document.formFoto.submit(); }; jQuery('#cmAddcontainer').show();" />   
                                    <input type="button" name="<?php echo $ix; ?>cmdCancel" id="<?php echo $ix; ?>cmdCancel" class="btn btn-info" value="Cancelar" onClick="loadTable();jQuery('#cmAddcontainer').show();" /> 
                                </div>
                            </th>
                        </tr>
                        <tr>
                            <td colspan="2">
                                <table width="100%" border="0" cellspacing="0" cellpadding="0">
                                    <?php
                                    if ($ix == 3) {
                                    ?>
                                        <tr>
                                            <td>EMPRESA</td>
                                            <td colspan="2">
                                                <select style="width:314px;" name="FK_EMPRESA" id="FK_EMPRESA">
                                                    <option value=""></option>
                                                    <?php
                                                    while( $arrTMP = each($arrEmpresas) ) {
                                                    ?>
                                                        <option <?php echo (isset($emp) ? ($arrTMP['value']['ID'] == $emp[0]['ID'] ? "selected='selected'" : "") : ""); ?> value="<?php print $arrTMP['value']['ID']; ?>"><?php print $arrTMP['value']['NOMBRE']; ?></option>
                                                     <?php
                                                     }
                                                     ?>
                                                </select>
                                            </td>
                                        </tr>
                                    <?php
                                    }
                                    if ($ix == 1) {
                                        ?>
                                        <tr>
                                            <td width="25%">* NOMBRES</td>
                                            <td width="25%">
                                                <input name="FIRST_NAME" type="text" value="" id="FIRST_NAME" size="30" maxlength="100" />
                                                -
                                                <input name="SECOND_NAME" type="text" value="" id="SECOND_NAME" size="30" maxlength="100" />
                                            </td>
                                            <td  >* APELLIDOS</td>
                                            <td >
                                                <input name="LAST_NAME"  type="text" id="LAST_NAME" size="60" maxlength="100" />
                                            </td>
                                        </tr>
                                        <tr>
                                            <td>* NO. CARNET</td>
                                            <td>
                                                <input name="ID" type="text" id="ID" onblur="javascript:document.formFoto.ID.value = document.<?php echo $mStudents->formName; ?>.ID.value;" />
                                            </td>
                                            <td >AIU CODE</td>
                                            <td>
                                                <input name="AIU_CODE" type="text" id="AIU_CODE" />
                                            </td>
                                        </tr>
                                        <tr>
                                            <td>* FECHA DE NACIMIENTO</td>
                                            <td>          
                                                <input name="BIRTH_DATE" readonly="readonly"  type="text" id="BIRTH_DATE" />
                                                <input name="STATUS" type="hidden" id="STATUS" value="1" />
                                            </td>
                                            <td >* SEXO</td>
                                            <td>
                                                <select name="GENDER" size="1" id="GENDER">
                                                    <option value="M">Masculino</option>
                                                    <option value="F">Femenino</option>
                                                </select>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td>EDAD</td>
                                            <td><h3><div id="edad"></div></h3></td>
                                            <td >FOTO</td>
                                            <td><a id="aFoto" href="#" onclick="javascript: document.formFoto.FOTO.click();">Seleccionar</a>&nbsp;<div id="divFoto"></div></td>
                                        </tr>
                                        <?php
                                    }
                                    $builder->build("cllg_student", NULL, $t['ID']);
                                    ?>
                                </table>
                            </td>
                        </tr>
                        <tr>
                            <td colspan="2">&nbsp;</td>
                        </tr>
                    </table>
                </div>
                <?php
            }
            ?> 
        </div>
    </div>
</form>
<form id="formFoto" name="formFoto" method="post" target="ifmFoto" action="<?php echo $mStudents->saveNewUrlPage; ?>" enctype="multipart/form-data">
    <input type="hidden" name="operation" value="sf" readonly="readonly"/>
    <input type="hidden" name="ID" id="ID" value="" readonly="readonly"/>
    <input type="file" name="FOTO" id="FOTO" style="display: none;" onchange="javascript: jQuery('#divFoto').html(jQuery('#FOTO').val());" />
</form>
<iframe name="ifmFoto" style="display: none;"></iframe>
<?php
$_SESSION['fields'] = serialize($builder->fieldsArray);
?>